<template>
	<view class="cart">
		<!-- 地址内容 -->
		<view class="address">
			<view class="top">
				<view class="name">
					收货人：<text>刘少华</text>
				</view>
				<view class="phone">
					15173038771
					<text>></text>
				</view>
			</view>
			<view class="center">
				收货地址：湖南省广东市开父打开了撒娇
			</view>
			<view class="bottom">
				<image src="../../static/cart_border@2x.png" mode=""></image>
			</view>
		</view>
		<!-- 购物车内容 -->
		<view class="shop">
			<view class="biaoti">
				<text class="iconfont icon-Group-"></text>优购生活馆
			</view>
			<view class="conment" v-for="(item,index) in allList" :key='index'>
				<view class="left">
					<icon v-if="item.status" type="success" color='red'></icon>
					<icon v-else type="success" color='gray'></icon>
				</view>
				<view class="right">
					<view class="img">
						<image :src="item.goods_small_logo" mode=""></image>
					</view>
					<view class="detail">
						<view class="top hide">
							{{item.goods_name }}
 						</view>
						<view class="bottom">
							<view class="pic">
								<text>￥</text><text>{{item.goods_price}}</text><text>.00</text>
							</view>
							<view class="total">
								<text>{{item.num}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 底部结算 -->
		<view class="footer">
			<view class="allIcon">
				<icon type="success" color='red'></icon>
			</view>
			<view class="all">全选</view>
			<view class="computer">
				<view class="top">
					合计：<text>￥14110.00</text>
				</view>
				<view class="bottom">
					包含运费
				</view>
			</view>
			<view class="fnal">
				结算（3）
			</view>
		</view>
	</view>
</template>

<script>
	import {
		goodslist
	} from "../../api/cart.js"
	export default {
		data() {
			return {
				// 购物车中的数据源
				cartList: [],
				// 所有数据的数组
				allList: []
			}
		},
		async onShow() {
			// 赋值
			this.cartList = uni.getStorageSync('cart')
			// 得到 cartList 中所有商品的 id 集合（字符串）
			let ids = this.cartList.map(item => {
				return item.goods_id
			}).join(',')
			console.log(ids)
			// 发送ajax请拿到数据
			const res = await goodslist(ids)
			let reslist = res.data.message
			// 所有数据数组
			this.allList = this.cartList.map(item => {
				// 拿到返回数据和 保存数据相同得数组
				let index = reslist.findIndex(
					resitem => {
						return resitem.goods_id == item.goods_id
					}
				)
				// 获得一个合并后的新数组
				return {
					...item,
					...reslist[index]
				}
			})
		},
    computed:{
			// 看是否全部选中
			all(){
		
			return
			}
		},
		methods: {

		}
	}
</script>

<style lang="less">
	.cart {
		background-color: #f4f4f4;
		padding-bottom: 120rpx;

		.address {
			background-color: #FFFFFF;
			padding-left: 20rpx;

			.top {
				margin-top: 40rpx;
				display: flex;
				justify-content: space-between;
				padding-right: 20rpx;

				.name {
					text {
						margin-left: 20rpx;
					}
				}

				.phone {
					text {
						color: #ccc;
						margin-left: 30rpx;
						margin-right: 15rpx;
					}
				}
			}

			.center {
				margin-top: 40rpx;

			}

			.bottom {
				margin-top: 20rpx;
				height: 15rpx;

				image {
					display: block;
					height: 15rpx;
					width: 100%;
				}
			}
		}

		.shop {
			background-color: #FFFFFF;
			margin-top: 20rpx;

			.biaoti {
				height: 88rpx;
				line-height: 88rpx;
				margin-left: 32rpx;
				border-bottom: 1px solid #dddddd;

				text {
					margin-right: 12rpx;
					color: #999999;
				}
			}

			.conment {
				display: flex;
				align-items: center;

				.left {
					width: 120rpx;
					text-align: center;

					icon {}
				}

				.right {
					padding: 20rpx 0;
					flex: 1;
					display: flex;
					border-bottom: 1px solid #dddddd;

					.img {
						width: 160rpx;

						image {
							width: 160rpx;
							height: 160rpx;
						}
					}

					.detail {
						padding: 0 20rpx;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.top {}

						.bottom {
							display: flex;
							justify-content: space-between;
							align-items: center;

							.pic {
								color: #eb4450;

								text:nth-child(1) {
									font-size: 14px;
								}

								text:nth-child(2) {
									font-size: 20px;
								}

								text:nth-child(3) {
									font-size: 16px;
								}
							}

							.total {}
						}
					}
				}

			}
		}

		.footer {
			height: 98rpx;
			position: fixed;
			left: 0;
			bottom: 0;
			width: 100%;
			background-color: #FFFFFF;
			display: flex;
			align-items: center;

			.allIcon {
				width: 120rpx;
				text-align: center;
			}

			.all {
				flex: 2;
			}

			.computer {
				flex: 4;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.top {
					text {
						color: #eb4450;
					}
				}

				.bottom {
					font-size: 12px;
					color: #999999;
				}
			}

			.fnal {
				flex: 3;
				line-height: 98rpx;
				text-align: center;
				background-color: #eb4450;
				color: #FFFFFF;
			}
		}
	}
</style>
